package com.net.xpay.admin.controller.admin;

import com.google.common.base.Preconditions;
import com.net.common.model.ResultData;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.notify.ChargeNotifyRecord;
import com.net.xpay.common.manager.notify.ChargeNotifyRecordManager;
import com.net.xpay.common.model.search.ChargeNotifyRecordSearchModel;

import com.net.xpay.core.model.IdModel;
import com.net.xpay.core.service.ChargeNotifyRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/charge-notify-record")
@Api(tags = "运营/转账回调记录", description = "运营 转账回调记录 net")
public class AdminChargeNotifyRecordController {

    @Autowired
    private ChargeNotifyRecordManager chargeNotifyRecordManager;

    @Autowired
    private ChargeNotifyRecordService chargeNotifyRecordService;
    /**
     * 搜索
     */
    @ApiOperation("搜索")
    @PostMapping("/search")
    public ResultPagedList<ChargeNotifyRecord> searchChargeNotifyRecord(@RequestBody ChargeNotifyRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        List<ChargeNotifyRecord> records = chargeNotifyRecordManager.search(searchModel);
        long count = chargeNotifyRecordManager.searchCount(searchModel);
        return new ResultPagedList<>(records, count, searchModel);
    }

    /**
     * 发起回调
     */
    @ApiOperation("发起回调")
    @PostMapping("/initiate")
    @PreAuthorize("hasAnyRole('ADMIN', 'charge-notify-record::initiate')")
    public ResultData<Boolean> initiateChargeNotify(@RequestBody IdModel model) {
        Preconditions.checkArgument(model != null);
        chargeNotifyRecordService.initiateChargeNotify(model.getId());
        return new ResultData<>(true);
    }
}
